<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>练习</title>
</head>

<body>
    <script>
        var name = 'The Window'
        var object = {
            name: 'My Object',
            getNameFunc: function () {
                return function () {
                    return this.name
                }
            }
        }
        // 注意：这里并没有闭包，内部函数并没有包含外部函数变量
        // 输出The Window；通过getNameFunc获取的是一个函数，然后再执行，所以获取的这个函数无调用者，this指向的是window
        console.log(object.getNameFunc()())


        var name2 = 'The Window'
        var object2 = {
            name2: 'My Object',
            getNameFunc: function () {
                var that = this
                return function (){
                    return that.name2
                }
            }
        }
        // 存在闭包
        console.log(object2.getNameFunc()())
    </script>
</body>

</html>